#include "key.h"

void keyinit()
{
RCC->APB2ENR|=1<<2;
GPIOA->CRL&=0xFFFFFFF0;
GPIOA->CRL|=0x00000008;//输入模式 默认下拉

RCC->APB2ENR|=1<<6;
GPIOE->CRL&=0xFFF00FFF;
GPIOE->CRL|=0x00088000;
GPIOE->ODR|=3<<3;	//PE3/4 上拉
}

u8 keyscan(u8 mode)			//mode=1则支持连续按
{
	static u8 keyup=1;
	u16 i;
	if(mode) keyup=1;			//连续按支持
	if(keyup&&(key0==0||key1==0||wkup==1))
	{
		delay_ms(10);
		keyup=0;
		if(key0==0) return 1;
		else if(key1==0) return 2;
		else if(wkup==1) return 3;
	}
	else if(key0==1&&key1==1&&wkup==0) keyup=1;
	return 0;
}
